<template>
  <div class="filter_container">
    <el-row align="middle" gutter="10">
      <template v-for="(item,index) in columnArr" :key="index">
        <el-col :span="item.span || 4"  v-if="item.search">
          <div class="form-item">
            <span :style="item.lableWidth?'width:'+item.lableWidth+'px':'width:50px'" class="span_text">{{item.name}}:</span>
            <el-select v-if="item.type=='select'" v-model="form[item.prop]" placeholder="请选择">
              <el-option
                v-for="(it,i) in item.options"
                :key="i"
                :label="it[item.optionValue || 'value']"
                :value="it[item.optionKey || 'key']">
              </el-option>
            </el-select>
            <el-input v-model="form[item.prop]"></el-input>
          </div>
        </el-col>
      </template>
      <el-col span="4">
        <div class="searchButton">
          <el-button v-if="search" size="medium" type="primary" icon="el-icon-search" @click.stop="filter">查询</el-button>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script lang="ts">
import {defineComponent} from 'vue'
export default defineComponent({
  props:{
    columnArr:{
      type:Array,
      default:[],
    },
    search:{
      type:Boolean,
      default:false,
    }
  },
  data(){
    return{
      form:{},
      formItemStyle:`width:200px`
    }
  },
  methods:{
    filter(){
      this.$emit("filter",this.form);
    }
  }
})
</script>
<style lang="less" scoped>
.filter_container{
  flex: 1;
  .filter_form{
    display: flex;
  }
  .form-item{
    height: 100%;
    display: flex;
    align-items: center;
    .span_text{
      flex-shrink: 0;
    }
  }
  .searchButton{
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }
}
</style>